import { MpInfoModel } from '@/models/mpInfo'
import { useModel, useSnapshot } from '@@/exports'
import { ModalForm, ProFormText } from '@ant-design/pro-components'
import { ProFormInstance } from '@ant-design/pro-form/lib'
import { useRef } from 'react'

export interface MpInfoUpdateModalProps {
  onFinish: (formData: any) => Promise<boolean | void>
}

const MpInfoUpdateModal = (props: MpInfoUpdateModalProps) => {
  let { getDictList } = useModel('dict')
  let mpInfoState = useSnapshot(MpInfoModel.state)
  let { actions: mpInfoActions } = MpInfoModel
  const formRef = useRef<ProFormInstance>()
  return (
    <>
      <ModalForm
        key={mpInfoState.mpInfo?.id || -1}
        formRef={formRef}
        title={mpInfoState.mpInfo ? '修改公众号信息' : '添加公众号信息'}
        open={mpInfoState.updateModalState}
        initialValues={mpInfoState.mpInfo}
        onFinish={props.onFinish}
        onOpenChange={mpInfoActions.setUpdateModalState}
      >
        <ProFormText label="id" name="id" rules={[{ required: true, message: '请填写id' }]} />

        <ProFormText label="token" name="token" rules={[{ required: true, message: '请填写token' }]} />

        <ProFormText label="aes_key" name="aesKey" rules={[{ required: true, message: '请填写aes_key' }]} />

        <ProFormText label="租户id" name="tenantId" rules={[{ required: true, message: '请填写租户id' }]} />
      </ModalForm>
    </>
  )
}

export default MpInfoUpdateModal
